//
//  WalkTrainingNode.h
//  ChampionRun
//
//  Created by MHD Yamen Saraiji on 11/10/13.
//
//

#ifndef __ChampionRun__WalkTrainingNode__
#define __ChampionRun__WalkTrainingNode__

#include "WalkNodeBase.h"
#include "libs/FANN/floatfann.h"
#include "libs/FANN/fann_cpp.h"

namespace cocos2d
{
    
class WalkTrainingNode:public WalkNodeBase
{
public:
    enum EStatus
    {
        EIdle,
        ESampling,
        ETraining,
        EFinished
    };
protected:
    
    struct TrainingVector
    {
        std::vector<float> inputs;
        std::vector<float> output;
    };
    EStatus m_status;
    FANN::neural_net * m_detectNet;
    FANN::training_data m_netData;
    std::vector<TrainingVector*> m_trainingSet;
    
    int m_currentTraining;
    int m_lastTrainingSample;
    
    void _updateHistogram();
    void _prepareNetwork();
    void _cleanData();
    
    int m_detectedCycle;
    
    TrainingVector* CreateVector();
public:
    
    WalkTrainingNode();
    virtual~WalkTrainingNode();

    static WalkTrainingNode* create()
    {
        WalkTrainingNode* node=new WalkTrainingNode();
        if(!node->init())
        {
            delete node;
            return NULL;
        }
        return node;
    }
    
    void RestartTraining();    
    bool NextTraining();
    void StartTraining();
    void Stop(){m_status=EIdle;}
    void EndTraining();
    int GetRemainingTraining();
    std::string GetCurrentTrainingLabel();
    
    float GetError();
    int GetCurrentSamples();
    int GetDetectedCycle(){return m_detectedCycle;}
    
    EStatus GetStatus(){return m_status;}
};
}


#endif /* defined(__ChampionRun__WalkTrainingNode__) */
